#include "addalert.h"

AddAlert::AddAlert()
{
    setupUi(this);
    connect(addAlertRecurring, SIGNAL(currentTextChanged(QString)), this, SLOT(checkRecurring(QString)));
    addAlertDateTime->setMinimumDateTime(QDateTime::currentDateTime());
    addAlertDateTime->setDateTime(QDateTime::currentDateTime());
    addAlertFrequency->setDisabled(true);
    a.setdisabled(false);
    setWindowFlags(Qt::WindowTitleHint | Qt::WindowMinimizeButtonHint);
    layout() -> setSizeConstraint(QLayout::SetFixedSize);
}
void AddAlert::construct(){
    if(this->addAlertName->text().isEmpty())
        QMessageBox::warning(this,"Add Alert","The alert you are attempting to enter has no name.",
                             QMessageBox::Ok);
    else{
        a.setdatetime(addAlertDateTime->dateTime());
        a.setinfo(addAlertInfo->toPlainText().toStdString());
        a.setname(addAlertName->text().toStdString());
        a.setnameid(a.getid().append(" ").append(a.getname()));
        add(a);
        this->close();
    }
}
void AddAlert::checkRecurring(QString string){
    if(string == "Yes"){
        a.setrecurring(true);
        a.setfrequency(addAlertFrequency->currentText().toStdString());
        addAlertFrequency->setDisabled(false);
    }
    else if(string == "No"){
        a.setrecurring(false);
        a.setfrequency("Never");
        addAlertFrequency->setDisabled(true);
    }
}
